< previous page page_187 next page >

Page 187
When you click the toolbar, only one event is triggered no matter which button you clicked. The toolbar click event uses a SELECTCASE statement to determine which button was clicked. You now have a choice to make concerning how to code the event routines for each button. This actually depends on the way you created the menu options. If you used unique names for each menu option, you can call the related menu routine from the toolbar click event routine as shown in Listing 7.3.
LISTING 7.3. TOOLOPTIONS.TXTTHE TOOLBAR ROUTINE CAN DIRECTLY ACCESS THE RELATED UNIQUE MENU OPTION ROUTINE.

8694cbadb9b1ef7075903f6f95fc1db2.gif
 1: Private Sub Toolbar1_ButtonClick(ByVal Button As ComctlLib.Button)
 2:     On Error Resume Next
 3:     Select Case Button.Key
 4:         Case New
 5:             Call mnuFileNew_Click
 6:         Case Open
 7:             Call mnuFileOpen_Click
 8:         Case Save
 9:             Call mnuFileSave_Click
10:     End Select
11: End Sub

However, if you decided to use the menu collection array for the different menu options, you would then either duplicate the menu option code in the toolbar event or call the menu click event, passing it the number that corresponds to the correct menu option. Listing 7.4 shows one way to handle the call when using collections.
LISTING 7.4. TOOLCOLLECT.TXTUSING THE MENU COLLECTION REQUIRES THE PASSING OF AN INDEX VALUE RELATED TO THE MENU OPTION.

8694cbadb9b1ef7075903f6f95fc1db2.gif
 1: Private Sub Toolbar1_ButtonClick(ByVal Button As ComctlLib.Button)
 2:     On Error Resume Next
 3:     Select Case Button.Key
 4:         Case New
 5:             Call mnuArray(1)
 6:         Case Open
 7:             Call mnuArray(2)
 8:         Case Save
 9:             Call mnuArray(3)
10:     End Select
11: End Sub

Your MDI parent form should now look like the one shown in Figure 7.15.

 
< previous page page_187 next page >

If you like this book, buy it!